const Mock = require('mockjs')

const data = Mock.mock({
  'items|90': [{
    ID: '@increment',
    Vendor: '@word(5, 21)',
    Address: '@county(true)',
    'Status|1': ['occupied', 'available', 'disabled', 'expired'],
    InsIdCd: '@string("number", 8)',
    ApplyTime: '@datetime',
    ExpireDate: '@date',
    PosUid: '@guid',
    MerchantName: '@cword(3, 10)',
    MerchantZone: '@province',
    'MerchantType|1': ['Retail', 'Accommodation', 'Catering'],
    Description: '@cparagraph'
  }]
})

module.exports = [
  {
    url: '/pos_admin/list\.*',
    type: 'get',
    response: config => {
      const { query } = config
      const result = []
      for (const index in data.items) {
        if (data.items[index].Vendor.includes(query.Vendor)) {
          result.push(data.items[index])
        }
      }
      return {
        Code: 20000,
        Data: {
          Total: result.length,
          Items: result
        }
      }
    }
  },

  {
    url: '/pos_admin/history\.*',
    type: 'get',
    response: config => {
      const { query } = config
      const result = Mock.mock({
        'items|0-6': [{
          'ID': '@integer(60, 100)',
          'CreatedAt': '@datetime',
          'UpdatedAt': '@datetime',
          'DeletedAt': null,
          'PosUid': query.PosUid,
          'Address': '@county(true)',
          'InsIdCd': '@string("number", 8)',
          'ApplyTime': '@datetime',
          'ExpireDate': '@datetime',
          'MerchantName': '@cword(3, 10)',
          'MerchantZone': 'MerchantZone',
          'MerchantType': '@province',
          'Description': '@cparagraph'
        }]
      })
      return {
        Code: 20000,
        Data: {
          Total: result.length,
          Items: result.items
        }
      }
    }
  }
]
